package me.hyman.testcustomview.progressbar;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import me.hyman.testcustomview.R;

/**
 * http://blog.csdn.net/lmj623565791/article/details/43371299
 */
public class ProgressBarActivity extends AppCompatActivity {

    private static final int MSG_PROGRESS_UPDATE = 0x110;

    private HorizontalProgressBarWithNumber horizontalProgressBarWithNumber;
    private RoundProgressBarWithNumber roundProgressBarWithNumber;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress_bar);

        horizontalProgressBarWithNumber = (HorizontalProgressBarWithNumber) findViewById(R.id.id_progressbar01);
        roundProgressBarWithNumber = (RoundProgressBarWithNumber) findViewById(R.id.id_progress02);

        handler.sendEmptyMessage(MSG_PROGRESS_UPDATE);
    }

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            int process = horizontalProgressBarWithNumber.getProgress();
            int roundProcess = roundProgressBarWithNumber.getProgress();
            horizontalProgressBarWithNumber.setProgress(++process);
            roundProgressBarWithNumber.setProgress(++roundProcess);
            if(process >= 100) {
                handler.removeMessages(MSG_PROGRESS_UPDATE);
            }

            handler.sendEmptyMessageDelayed(MSG_PROGRESS_UPDATE, 100);
        }
    };
}
